package games.platformer.behaviors;
import vooga.core.Sound;

/**
 * adapted by Jonathan Odom for Vooga
 * 
 * this version of the Behavior plays a sound when an item is removed
 * 
 * @author Robert C. Duvall
 * @author bshelton
 */
public class IntersectAndRemoveSound extends IntersectAndStop
{
    private vooga.core.AbstractLevel myLevel;
    
    private Sound mySound;


    public IntersectAndRemoveSound (vooga.geom.Vector velocity,
                               vooga.entities.Entity obstacle,
                               vooga.core.AbstractLevel level, String sound)
    {
        super(velocity, obstacle);
        myLevel = level;
        mySound = new Sound(sound);
    }

    public IntersectAndRemoveSound (vooga.geom.Vector velocity,
                               java.util.List<vooga.entities.Entity> obstacles,
                               vooga.core.AbstractLevel level, String sound)
    {
        super(velocity, obstacles);
        myLevel = level;
        mySound = new Sound(sound);
    }
    
    public IntersectAndRemoveSound (vooga.geom.Vector velocity,
            java.util.Collection<vooga.entities.Entity> obstacles,
            vooga.core.AbstractLevel level, String sound)
    {
    	super(velocity, obstacles);
    	myLevel = level;
    	mySound = new Sound(sound);
	}


    protected void onCollide (vooga.entities.Entity lhs, vooga.entities.Entity rhs)
    {
        mySound.play();
    	super.onCollide(lhs, rhs);
        
        myLevel.removeEntity(rhs.getClass().cast(rhs));
        System.out.println(rhs.getClass().getName());
        //myLevel.removeEntity(rhs.getClass().cast(vooga.util.Reflection.createInstance(rhs.getClass().getName())));
        remove(rhs);
    }
}
